//
//  XCAttentionSearchContentController.m
//  XCNewsApp
//
//  Created by FAITH on 16/12/9.
//  Copyright © 2016年 XC. All rights reserved.
//

#import "XCAttentionSearchContentController.h"
#import "XCInterestContentView.h"
#import "FAITHHttpTool.h"
@interface XCAttentionSearchContentController ()<UISearchBarDelegate>
@property(nonatomic,strong) UISearchBar *searchBar;
@end

@implementation XCAttentionSearchContentController
//懒加载
-(UISearchBar *)searchBar
{
    if (_searchBar==nil){
        UISearchBar *searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 44)];
        
        searchBar.placeholder=@"请输入关键字";
        
        searchBar.delegate=self;
        
        _searchBar=searchBar;
        
    }
    return _searchBar;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.titleView=self.searchBar;
    
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(cancelBtnClick)];
    
    [self.searchBar becomeFirstResponder];
    
    [self setUpUI];
    
}

-(void)cancelBtnClick
{
    self.cancelBtnBlock();
}

-(void)setUpUI
{
    
    
    NSArray *menuArray=@[@{
                             @"name":@"文章",
                             @"image":@"essay_discover"
                             },@{
                             @"name":@"频道",
                             @"image":@"channel_discover"
                             },@{
                             @"name":@"头条号",
                             @"image":@"pgc_discover"
                             },@{
                             @"name":@"视频",
                             @"image":@"video_discover"
                             
                             },@{
                             @"name":@"话题",
                             @"image":@"topic_discover"
                             
                             }];

    
    XCInterestContentView *interestContentView=[XCInterestContentView menuViewWithArray:menuArray viewHeight:80];
    
    interestContentView.center=CGPointMake(self.view.centerX, self.view.centerY-100);

    [self.view addSubview:interestContentView];
}

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
//    http://lf.snssdk.com/2/article/search_sug/?version_code=5.8.5&app_name=news_article&vid=AE8B93E7-AF12-497D-B605-E394BECCA2B9&device_id=10723815300&channel=App%20Store&resolution=1242*2208&aid=13&ab_version=90171,83097,87331,93903,94664,93822,94006,82679,93319,92439,93526,92518,94163,94790,94005,87495,94936,87988&ab_feature=z2&ab_group=z2&openudid=d41d8cd98f00b204e9800998ecf8427ef2339ea7&live_sdk_version=1.3.0&idfv=AE8B93E7-AF12-497D-B605-E394BECCA2B9&ac=WIFI&os_version=9.1&ssmix=a&device_platform=iphone&iid=6314617356&ab_client=a1,f2,f7,e1&device_type=iPhone%206%20Plus&idfa=4BAD76A0-89BD-41EA-92EC-92FF39DBAAE1&from=search_tab&keyword=%E6%88%91
    NSDictionary *params= @{
                           
                            @"from" : @"search_tab",
                            @"keyword" : searchText
                            };
   
    
    
    [FAITHHttpTool get:[NSString stringWithFormat:@"%@2/article/search_sug/",baseUrl] params:params success:^(id responseObj) {
        NSLog(@"%@",responseObj);
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];

    
    
}

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    NSDictionary *params= @{
                            @"version_code" : @"5.8.5",
                            @"app_name" : @"news_article",
                            @"vid" : @"AE8B93E7-AF12-497D-B605-E394BECCA2B9",
                            @"device_id" : @"10723815300",
                            @"channel" : @"App%20Store",
                            @"resolution" : @"1242*2208",
                            @"aid" : @"13",
                            
                            @"ab_version" : @"90171,83097,89186,87331,93903,93822,94055,93419,92848,93981,94006,82679,93319,92439,93526,93357,92518,94005,92485,87495,93888,87988",
                            @"ab_feature" : @"z2",
                            @"ab_group" : @"z2",
                            @"openudid" : @"d41d8cd98f00b204e9800998ecf8427ef2339ea7",
                            @"live_sdk_version" : @"1.3.0",
                            @"idfv" : @"AE8B93E7-AF12-497D-B605-E394BECCA2B9",
                            @"ac" : @"WIFI",
                            @"os_version" : @"9.1",
                            @"ssmix" : @"a",
                            @"device_platform" : @"iphone",
                            @"iid" : @"6314617356",
                            @"ab_client" : @"a1,f2,f7,e1",
                            @"device_type" : @"iPhone%206%20Plus",
                            @"idfa" : @"4BAD76A0-89BD-41EA-92EC-92FF39DBAAE1",
                            @"LBS_status" : @"authroize",
                            @"city" : @"%E5%B9%BF%E5%B7%9E",
                            @"concern_id" : @"6286225228934679042",
                            @"count" : @"20",
                            @"cp" : @"5a814a639d038q1",
                            @"detail" : @"1",
                            @"image" : @"1",
                            @"language" : @"zh-Hans-CN",
                            @"last_refresh_sub_entrance_interval" : @"1481019448",
                            @"latitude" : @"23.1331997900028",
                            @"loc_mode" : @"1",
                            @"loc_time" : @"1481019127",
                            @"longitude" : @"113.3674360500047",
                            @"min_behot_time" : @"1481019411",
                            @"refer" : @"1",
                            @"strict" : @"0",
                            @"tt_from" : @"pull HTTP/1.1",
                            @"from" : @"search_tab",
                            @"keyword" : searchBar.text
                            };
    
    
    
    [FAITHHttpTool get:[NSString stringWithFormat:@"%@2/article/search_sug/",baseUrl] params:params success:^(id responseObj) {
        NSLog(@"%@",responseObj);
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

@end
